#ifndef EPUBDUKPT_CONTEXT_PARAMS2_HPP
#define EPUBDUKPT_CONTEXT_PARAMS2_HPP

SJR_NAMESPACE_BEGIN

class EpubContextParams2 : public EpubContextParams1 {
public:
  constexpr static int KSI_SIZE = 5;

  EpubContextParams2() : EpubContextParams1(), mKSI(KSI_SIZE) {
    memset(&mKSI[0], 0xFF, mKSI.size());
  }

  auto ksi() -> std::vector<unsigned char> & {
    return mKSI;
  }

  void setKSI(unsigned char const *in, int inLen) {
    int j = 0;
    memset(&mKSI[0], 0xFF, mKSI.size());
    auto &&autLen = mKSI.size() - (inLen > mKSI.size() ? mKSI.size() : inLen);
    for (int i = static_cast<int>(autLen); i < mKSI.size(); ++i) {
      mKSI[i] = (((in[j] >> 0x04u) == 0) ? 0xF0 : in[j] & 0xF0u) +
                (((in[j] & 0x0Fu) == 0) ? 0x0Fu : in[j] & 0x0F);
      ++j;
    }
  }

private:
  std::vector<unsigned char> mKSI;
};

SJR_NAMESPACE_END

#endif//EPUBDUKPT_CONTEXT_PARAMS2_HPP
